import tensorflow as tf

#v1 = tf.Variable(tf.constant(1.0,shape=[1]),name='V1')
#v2 = tf.Variable(tf.constant(2.0,shape=[1]),name='V2')
v1 = tf.compat.v1.placeholder(tf.float32,shape=[1,None],name='V1')
alph = tf.Variable(tf.constant(0.5,tf.float32,shape=[1,1]),name='alf')
v2 = tf.compat.v1.placeholder(tf.float32,shape=[1,None],name='V2')
mutl = tf.math.multiply(alph, v1)
result = tf.add(mutl,v2,name='add_op')

init_op = tf.compat.v1.global_variables_initializer()

with tf.compat.v1.Session() as sess:
    sess.run(init_op)

    builder = tf.compat.v1.saved_model.builder.SavedModelBuilder("./demo3/half_plus")

    inputs = {"input_x": tf.compat.v1.saved_model.utils.build_tensor_info(v1),
             "input_y": tf.compat.v1.saved_model.utils.build_tensor_info(v2)}
    outputs = {'output': tf.compat.v1.saved_model.utils.build_tensor_info(result)}
    predict_signature_def = (
        tf.saved_model.signature_def_utils.build_signature_def(
            inputs, outputs,
            tf.saved_model.signature_constants.PREDICT_METHOD_NAME))

    signature = tf.compat.v1.saved_model.signature_def_utils.build_signature_def(inputs, outputs, 'test_sig_name')

    builder.add_meta_graph_and_variables(sess,[tf.compat.v1.saved_model.tag_constants.SERVING],{tf.compat.v1.saved_model.signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY :predict_signature_def})

    builder.save()
